<?php
/**
 * Created by PhpStorm.
 * User: chenjunjie
 * Date: 2020/8/26
 * Time: 11:58 AM
 */
declare(strict_types = 1);
namespace App\Controller\Auth;

use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerInterface;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;

class Controller
{
    /**
     * @Inject
     *
     * @var ContainerInterface
     */
    protected $container;
    /**
     * @Inject
     *
     * @var RequestInterface
     */
    protected $request;
    /**
     * @Inject
     *
     * @var ResponseInterface
     */
    protected $response;
    /**
     * 请求成功
     *
     * @param        $data
     * @param string $message
     *
     * @return array
     */
    public function success($data, $message = 'success')
    {
        $code = $this->response->getStatusCode();
        return ['message' => $message, 'code' => $code, 'data' => $data];
    }
    /**
     * 请求失败.
     *
     * @param string $message
     *
     * @return array
     */
    public function failed($message = 'Request format error!')
    {
        return ['message' => $message, 'code' => 500, 'data' => ''];
    }

    /**
     * @param null $result
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function successJsonResponse($result = null){

        return $this->response->json([
            'code' => 200,
            'data' => $result,
            'msg' => '操作成功'
        ]);
    }
    public  function successFootJsonResponse($result = null,$message=null,$code = 200){

        return $this->response->json([
            'code' => $code,
            'data' => $result,
            'message' => $message
        ]);
    }
    public function errorJsonResponse($code = 300,$result = null){

        return $this->response->json([
            'code' => $code,
            'data' => ["userId"=>0],
            'msg' => $result
        ]);
    }


}